<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" placeholder="输入关键词" v-focus>
    </div>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    Vue.directives('focus',{
        inserted(el){
            el.focus()
        }
    })
    var v =new Vue({
        el:'#app',
        directives:{
            //函数形式   局部定义
            // focus(el){
            //     console.log('focus');
            //     el.focus()
            // }
            //对象形式
            focus:{
                //insert(el){
                    inserted(el){    //el 指令所在的标签
                        el.focus()   //让表单元素获得焦点
                    }
            }
        }
    })
</script>